#include "Input_Win32.h"
#include <algorithm>

Input_Win32::Input_Win32()
	: Service<Input_Win32>( this )
{
	for( int i(0); i < IA_NumberOf; ++i )
	{
		m_keys[i] = IT_KeyUp;
	}
}

void Input_Win32::Update(UINT message, WPARAM wParam)
{
	switch (message)
	{
	case WM_KEYDOWN:
		{
			switch(wParam)
			{
			case VK_LEFT:
			case 'A':
				{
					m_keys[IA_Left] = IT_KeyDown;

					OutputDebugString(TEXT("LEFT\n"));
				}
				break;
			case VK_UP:
			case 'W':
				{
					m_keys[IA_Up] = IT_KeyDown;

					OutputDebugString(TEXT("UP\n"));
				}
				break;
			case VK_DOWN:
			case 'S':
				{
					m_keys[IA_Down] = IT_KeyDown;

					OutputDebugString(TEXT("DOWN\n"));
				}
				break;
			case VK_RIGHT:
			case 'D':
				{
					m_keys[IA_Right] = IT_KeyDown;

					OutputDebugString(TEXT("RIGHT\n"));
				}
				break;
			}
		}
		break;

	case WM_KEYUP:
		{
			switch(wParam)
			{
			case VK_LEFT:
			case 'A':
				{
					m_keys[IA_Left] = IT_KeyUp;

					OutputDebugString(TEXT("LEFT\n"));
				}
				break;
			case VK_UP:
			case 'W':
				{
					m_keys[IA_Up] = IT_KeyUp;

					OutputDebugString(TEXT("UP\n"));
				}
				break;
			case VK_DOWN:
			case 'S':
				{
					m_keys[IA_Down] = IT_KeyUp;

					OutputDebugString(TEXT("DOWN\n"));
				}
				break;
			case VK_RIGHT:
			case 'D':
				{
					m_keys[IA_Right] = IT_KeyUp;

					OutputDebugString(TEXT("RIGHT\n"));
				}
				break;
			}
		}
		break;
	}

}

InputType Input_Win32::GetInput( InputAction action )
{
	return m_keys[action];
}